#ifndef X23_H
#define X23_H

#include "common.h"

// Connection (rat). Draws a line between two connected pads.
template <AllegroVersion version>
struct x23
{
    uint16_t type;
    uint8_t subtype;
    uint8_t layer;
    
    uint32_t k;
    
    // Another `x23`
    uint32_t ptr0;
    
    uint32_t bitmask[2];
    
    // Matching placed symbol pad (`x32`)
    uint32_t ptr1;
    
    // Another `x23`
    uint32_t ptr2;
    
    // Another `x32`
    uint32_t ptr3;
    
    int32_t coords[5];
    
    uint32_t un[4];
    
    uint32_t TAIL;
    operator x23<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_164, A_174};
};

#if __cplusplus >= 202002L
template <AllegroVersion version> requires(version >= A_164)
struct x23<version>
{
    uint16_t type;
    uint8_t subtype;
    uint8_t layer;

    uint32_t k;

    // Another `x23`
    uint32_t ptr0;

    uint32_t bitmask[2];

    // Matching placed symbol pad (`x32`)
    uint32_t ptr1;

    // Another `x23`
    uint32_t ptr2;

    // Another `x32`
    uint32_t ptr3;

    int32_t coords[5];

    uint32_t un[4];
    uint32_t un2[4];
    COND_FIELD(version >= A_174, uint32_t, un1);

    uint32_t TAIL;
    operator x23<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_164, A_174};
};
#else
template <> struct x23<A_164>
{
    uint16_t type;
    uint8_t subtype;
    uint8_t layer;

    uint32_t k;

    // Another `x23`
    uint32_t ptr0;

    uint32_t bitmask[2];

    // Matching placed symbol pad (`x32`)
    uint32_t ptr1;

    // Another `x23`
    uint32_t ptr2;

    // Another `x32`
    uint32_t ptr3;

    int32_t coords[5];

    uint32_t un[4];
    uint32_t un2[4];

    uint32_t TAIL;
    operator x23<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_164, A_174};
};
template <> struct x23<A_165> : x23<A_164> {};
template <> struct x23<A_166> : x23<A_164> {};

template <> struct x23<A_174>
{
    uint16_t type;
    uint8_t subtype;
    uint8_t layer;

    uint32_t k;

    // Another `x23`
    uint32_t ptr0;

    uint32_t bitmask[2];

    // Matching placed symbol pad (`x32`)
    uint32_t ptr1;

    // Another `x23`
    uint32_t ptr2;

    // Another `x32`
    uint32_t ptr3;

    int32_t coords[5];

    uint32_t un[4];
    uint32_t un2[4];
    uint32_t un1;

    uint32_t TAIL;
    operator x23<A_174>() const;
    static constexpr AllegroVersion versions[2] = {A_164, A_174};
};

#endif

#endif // X23_H
